<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>


//通过 .[]添加的属性是可修改、可枚举、可写的 configurable/enumerable/writable

        let obj = {x:1,y:20}
        obj.z = 30
        Object.defineProperty(obj,'t',{
            value:100
        })
        console.log(obj) // {x: 1, y: 20, z: 30, t: 100}

//通过 Object.defineProperty添加的属性默认是不可修改、不可枚举、不可写的 configurable/enumerable/writable
/*
        configurable: 删除操作
        enumerable： for in  遍历操作
        writable： 改变值
*/
        obj.y = 300
        obj.t = 10000 
        console.log(obj) // {x: 1, y: 300, z: 30, t: 100}

        delete obj.y
        console.log(obj) // {x: 1, z: 30, t: 100}

        // delete obj.t
        // console.log(obj) // 报错：Uncaught TypeError: Property description must be an object: undefined

        Object.defineProperty(obj,'k',{
            value:70,
            configurable:true,
            enumerable:true,
            writable:true
        })

        console.log(obj) // {x: 1, z: 30, k: 70, t: 100}

        obj.k = 7000
        console.log(obj) // {x: 1, z: 30, k: 7000, t: 100}

        delete obj.k
        console.log(obj) // {x: 1, z: 30, t: 100}
    </script>
</body>
</html>